﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using LinQ_DTO;

namespace DAO
{
    public class KhuyenMaiDAO
    {

        public List<shop_khuyenmai> LayTatCaKhuyenMai()
        {
            EFashionDBDataContext EFashionDB = new EFashionDBDataContext();
            var List = from c in EFashionDB.shop_khuyenmais select c;
            return List.ToList();
        }

       

       
        public shop_khuyenmai LayKhuyenMaiTheoMa(int Ma)
        {
            EFashionDBDataContext EFashionDB = new EFashionDBDataContext();
            shop_khuyenmai select = EFashionDB.shop_khuyenmais.Single(c => c.MaKhuyenMai == Ma);
            return select;
        }

        public void ThemKhuyenMai(shop_khuyenmai a)
        {
            EFashionDBDataContext EFashionDB = new EFashionDBDataContext();
            EFashionDB.shop_khuyenmais.InsertOnSubmit(a);
            EFashionDB.SubmitChanges();

        }

        public void XoaKhuyenMaiTheoMa(int Ma)
        {

            EFashionDBDataContext EFashionDB = new EFashionDBDataContext();
            var List = from a in EFashionDB.shop_khuyenmais
                       where a.MaKhuyenMai == Ma
                       select a;
            shop_khuyenmai ResultCmt = List.Single();
            EFashionDB.shop_khuyenmais.DeleteOnSubmit(ResultCmt);
            EFashionDB.SubmitChanges();

        }

        public void CapNhatKhuyenMai(shop_khuyenmai a)
        {

            EFashionDBDataContext EFashionDB = new EFashionDBDataContext();
            shop_khuyenmai select = EFashionDB.shop_khuyenmais.Single(c => c.MaKhuyenMai == a.MaKhuyenMai);
            if (select != null)
            {
                select.LoaiKhuyenMai = a.LoaiKhuyenMai;
                select.MucKhuyenMai = a.MucKhuyenMai;
                select.NgayBatDau = a.NgayBatDau;
                select.NgayKetThuc = a.NgayKetThuc;
                select.NoiDung = a.NoiDung;
               
            }
            EFashionDB.SubmitChanges();
        }
/////////////////////////////////////////////////////////////////////////////////////////////

         
    }
}
